<?php

class Settings {

	public $activeLeague;
	public $activeSeason;
	public $currentRound;
	
	public $base;
	
	// constructor
	
	public function __construct() {
		$this->activeLeague = intval($this->getParameter("activeLeague"));
		$this->activeSeason = intval($this->getParameter("activeSeason"));
		$this->currentRound = intval($this->getParameter("currentRound"));
		$this->base = $this->getParameter("base");
	}
	
	// functions
	
	private function getParameter($p) {
		$q = "SELECT value FROM settings WHERE parameter = '" . $p ."'";
		$r = mysql_query("set names 'utf8'");
		$r = mysql_query($q);
		if (!mysql_num_rows($r)) throw new Exception("There is no parameter named " . $p . "!");
		$n = mysql_fetch_array($r);
		return ($n[0]);
	}
	
	// admin
	
	public function updateParameter($p, $v) {
		$q = "UPDATE settings SET value = " . $v . " WHERE parameter = " . $p;
		$r = mysql_query("set names 'utf8'");
		if (mysql_query($q)) {
			echo "Nova opcija je dodata u bazu podataka";
		}
	}

		
} // end of class Settings


?>